<template>
  <div class="details-box">
    <!-- 工单审核 -->
    <!-- 表单信息 -->
    <Tickets @subSearch="subSearch"/>
    <!-- 表格信息 -->
    <Table :detailsBtnFlag="false" :detailsCheck="checkPermi(['system:order:check'])" :isfalse="false" :iswidth="iswidth" :limit="pageSize"
           :page="pageNum" :tableData="tableData" :total="total" @handleChange="handleChange"
            @searchNewListApi="searchNewListApi"/>
  </div>
</template>
<script setup>
import {onMounted, ref} from 'vue'
import {useRoute} from 'vue-router'
import Table from '@/components/table/indexs.vue'
import Tickets from '@/components/Tickets'
import {getselectOrderApi} from '@/api/tickets/index.js'
import {checkPermi} from "@/utils/permission.js";
import dayjs from 'dayjs'

let idActive = 'orderId'
let route = useRoute()
let total = ref(100)
let pageNum = ref(1)    // 页数
let pageSize = ref(50)  // 条数
// 存放用户搜索的数据
let userSearchList = ref({})
// 表单数据
const tableData = ref([])
let iswidth = true
// 未收款接口
let getselectOrderData = async (params) => {
  let res = await getselectOrderApi(params)
  let {code, rows} = res
  if (code === 200) {
    total.value = res.total
    tableData.value = rows
  }
}
// 分页器
const handleChange = (v) => {
    let { page, limit } = v.page

    pageNum.value = page
    pageSize.value = limit
    let obj = {
      pageNum: pageNum.value,
      pageSize: pageSize.value,
    }
    let params = Object.assign(obj, userSearchList.value)
    params.orderDateLte = userSearchList.value.orderDateLte
    params.orderDateGte = userSearchList.value.orderDateGte
    delete params.orderDate
    getselectOrderData(params)
}

let orderDateLte = ref('');
let orderDateGte = ref('');

// 查询
const subSearch = (v) => {
  let obj = {
    pageNum: pageNum.value,
    pageSize: pageSize.value,
  }
  let paramss = {
    orderDateLte: v.orderDate ? v.orderDate[0] : null,
    orderDateGte: v.orderDate ? dayjs(v.orderDate[1]).subtract(1,'second').format('YYYY-MM-DD HH:mm:ss') : null,
    ...v
  }
  userSearchList.value = v

  paramss.orderDate = null
  pageNum.value = 1
  let params = Object.assign(obj, paramss)
  getselectOrderData(params)
}

const searchNewListApi = () => {

  
  let obj = {
    paymentStatus: route.query.state,
    invoiceStatus: '待审核',
    pageNum: pageNum.value,
    pageSize: pageSize.value,
  }
  let params = Object.assign(obj, userSearchList.value)
  params.orderDateLte = userSearchList.value.orderDateLte
  params.orderDateGte = userSearchList.value.orderDateGte
  params.orderDate=null
  getselectOrderData(params)
}
onMounted(() => {
  let params = {
    paymentStatus: route.query.state,
    pageNum: pageNum.value,
    pageSize: pageSize.value,
    invoiceStatus: '待审核'
  }
  getselectOrderData(params)
})
</script>
<style lang='scss' scoped></style>
